package fr.umlv.m2.jee.spij.persistence.education;

import fr.umlv.m2.jee.spij.persistence.actor.StudentTutorial;
import fr.umlv.m2.jee.spij.persistence.actor.TeacherTutorial;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity Tutorial who contain information about tutorial.
 *
 * @author Lounes Akroune
 * @author Aurelien Scelles
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "TUT_TUTORIAL")
public class Tutorial extends Practice {

    /**
     * Primary key.
     */
    @Id
    @Column(name = "TUT_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long id;

    /**
     * Id of linked unit.
     */
    @Column(name = "TUT_UNI_ID")
    private Long unit;


    /**
     * List of students
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "ST_TUTORIAL_ID", referencedColumnName = "TUT_ID")
    private List<StudentTutorial> students = new ArrayList<StudentTutorial>();

    /**
     * List of teachers
     */
    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "TT_TUTORIAL_ID", referencedColumnName = "TUT_ID")
    private List<TeacherTutorial> teachers = new ArrayList<TeacherTutorial>();

    /**
     * Setter of id.
     *
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Getter of id.
     *
     * @return primary key
     */
    public long getId() {
        return id;
    }

    /**
     * Setter of unit.
     *
     * @param unit
     */
    public void setUnit(Long unit) {
        this.unit = unit;
    }

    /**
     * Getter of unit.
     *
     * @return id of linked unit
     */
    public Long getUnit() {
        return unit;
    }

    public void setStudents(List<StudentTutorial> students) {
        this.students = students;
    }

    public List<StudentTutorial> getStudents() {
        return students;
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addStudent(StudentTutorial arg0) {
        return students.add(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public StudentTutorial getStudent(int arg0) {
        return students.get(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeStudent(Object arg0) {
        return students.remove(arg0);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfStudents() {
        return students.size();
    }

    public void setTeachers(List<TeacherTutorial> teachers) {
        this.teachers = teachers;
    }

    public List<TeacherTutorial> getTeachers() {
        return teachers;
    }

    /**
     * @param e
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean addTeacher(TeacherTutorial e) {
        return teachers.add(e);
    }

    /**
     * @param index
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public TeacherTutorial getTeacher(int index) {
        return teachers.get(index);
    }

    /**
     * @param o
     *
     * @return
     *
     * @see java.util.List#remove(java.lang.Object)
     */
    public boolean removeTeacher(Object o) {
        return teachers.remove(o);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int numberOfTeachers() {
        return teachers.size();
    }
}
